<?php

namespace app\common\model;

use think\Model;

class Progress extends Model
{
    // 表名
    protected $name = 'progress';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'progress_type_text',
        'progress_submit_time_text',
        'progress_add_time_text',
        'progress_status_text',
        'progress_flag_text',
        'last_update_time_text'
    ];
    

    
    public function getProgressTypeList()
    {
        return ['1' => __('Progress_type 1')];
    }     

    public function getProgressStatusList()
    {
        return ['1' => __('Progress_status 1')];
    }     

    public function getProgressFlagList()
    {
        return ['2' => __('Progress_flag 2')];
    }     


    public function getProgressTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['progress_type'];
        $list = $this->getProgressTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getProgressSubmitTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['progress_submit_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getProgressAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['progress_add_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getProgressStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['progress_status'];
        $list = $this->getProgressStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getProgressFlagTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['progress_flag'];
        $list = $this->getProgressFlagList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['last_update_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setProgressSubmitTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setProgressAddTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLastUpdateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
